import { describe, expect, it } from "vitest"
import { calculateSubpath, parsePathD } from "@/modules/calculation/curve"

describe("calculateSubpath", () => {
  describe("subpath of bezier curve", () => {
    const pathD = "M 80 80 Q 120 63 160 63 Q 200 63 240 80"
    const segments = parsePathD(pathD)
    it("should calculate correctly: applying margin", () => {
      let subpath = calculateSubpath(segments, 0, 0)
      expect(subpath).equals("M 80 80 Q 120 63 160 63 Q 200 63 240 80")

      subpath = calculateSubpath(segments, 30, 30)
      expect(subpath).equals(
        "M108.30078125,70.09964948892593C125.53385416666666,65.36654982964197,142.76692708333331,63,160,63C177.23307291666663,63,194.46614583333331,65.36654982964197,211.69921874999997,70.09964948892593"
      )

      subpath = calculateSubpath(segments, 30, 0)
      expect(subpath).equals(
        "M108.30078125,70.09964948892593C125.53385416666666,65.36654982964197,142.76692708333331,63,160,63C186.66666666666663,63,213.33333333333331,68.66666666666666,240,80"
      )

      subpath = calculateSubpath(segments, 0, 30)
      expect(subpath).equals(
        "M80,80C106.66666666666666,68.66666666666666,133.33333333333331,63,160,63C177.23307291666663,63,194.46614583333331,65.36654982964197,211.69921874999997,70.09964948892593"
      )
    })
  })

  // describe("subpath of arc", () => {
  //   const pathD = "M 70 80 A 29 29 0 1 1 70 79";
  //   const segments = parsePathD(pathD)
  //   it("should calculate correctly: applying margin", () => {

  //     let subpath = calculateSubpath(segments, 0, 0)
  //     expect(subpath).equals(
  //       "M 70 80 A 29 29 0 1 1 70 79"
  //     )

  //     subpath = calculateSubpath(segments, 30, 30)
  //     expect(subpath).equals(
  //       "M55.4181444325443,104.66435316333775C46.8257637070537,109.58274975000052,35.7732842754285,110.18646400408264,26.073453303630487,104.36100356880922C6.9354438332621555,92.86722421289402,7.416569048926579,64.96610914143933,26.93947869182646,54.13899644019079C36.47016922240115,48.85341850213058,47.09500723603882,49.57253869044651,55.40663375181794,54.32911738247944"
  //     )

  //     subpath = calculateSubpath(segments, 30, 0)
  //     expect(subpath).equals(
  //       "M55.4181444325443,104.66435316333775C46.8257637070537,109.58274975000052,35.7732842754285,110.18646400408264,26.073453303630487,104.36100356880922C6.9354438332621555,92.86722421289402,7.416569048926579,64.96610914143933,26.93947869182646,54.13899644019079C46.075610266941126,43.52638505083068,69.62272527612058,57.12131823110912,70,79"
  //     )

  //     subpath = calculateSubpath(segments, 0, 30)
  //     expect(subpath).equals(
  //       "M70,80C69.61509982746846,102.32089205716375,45.21146277399882,115.85478292472442,26.073453303630487,104.36100356880922C6.9354438332621555,92.86722421289402,7.416569048926579,64.96610914143933,26.93947869182646,54.13899644019079C36.47016922240115,48.85341850213058,47.09500723603882,49.57253869044651,55.40663375181794,54.32911738247944"
  //     )
  //   })
  // })
})
